package com.xujl.demo;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.support.annotation.Nullable;
import android.widget.Toast;

import com.changan.remote.assistant.RemoteDelegate;

/**
 * <pre>
 *     @author : xujl
 *     e-mail : 597355068@qq.com
 *     time   : 2018/11/8
 *     desc   :
 *     version: 1.0
 * </pre>
 */
public class TestService extends Service implements RemoteDelegate.ReceiveEventListener {
    private RemoteDelegate mRemoteDelegate;

    @Override
    public void onCreate () {
        super.onCreate();
        mRemoteDelegate = new RemoteDelegate(this);
    }

    @Nullable
    @Override
    public IBinder onBind (Intent intent) {
        return mRemoteDelegate.getIBinder();
    }

    @Override
    public void onReceiveEvent (String json) {
        Toast.makeText(this, json, Toast.LENGTH_SHORT).show();
    }

    @Override
    public int onStartCommand (Intent intent, int flags, int startId) {
        mRemoteDelegate.dispatchEvent(0, "测试json2");
        mRemoteDelegate.dispatchEvent(1, "测试json3");
        return super.onStartCommand(intent, flags, startId);
    }
}
